package cn.com.callback

import cn.com.elite.EliteBean
import cn.com.elite.Util
import net.sf.json.JSONObject
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory


/**
 *
 * @author Rick
 * @use 获取华为电话信息
 *
 *
 */
public class apiHWcallUpdate implements CallBackInvoke {
	private static final Log log=LogFactory.getLog(apiHWcallUpdate.class);

	public void doCallBack(EliteBean eliteBean, String callBack, Map map, String paramString) {

		def smap;
		try {

			smap = eliteBean.chaxun_sql("select ATTACHEDDATA from EVENT where CALLSTARTTIME<sysdate-10/1440 and CALLSTARTTIME>sysdate-1/12 and nvl(stringfield2,'')='' and nvl(ATTACHEDDATA,'')!=''","dataSource");
			if(smap.size()==0){
				log.debug("未查到可更新数据");
			}else{
				for(int i=0;i < smap.size();i++){
					log.debug("当前更新callid:"+smap[i].getAt("ATTACHEDDATA"));
					UpdateCall(eliteBean,smap[i].getAt("ATTACHEDDATA"));
				}
			}

		}catch (Exception e) {
			log.error("errormsg:", e)
		}
	}


/**
 *
 * @use 查询华为数据表并更新至event,record
 * @param eliteBean
 * @param callid
 * @return
 */
	private String UpdateCall(EliteBean eliteBean,callid) {
		def smap,releasecause,hanguptype="";
		try {
			//获取华为数据
			smap = eliteBean.chaxun_sql("select releasecause from tcurrentbilllog where callid='"+callid+"'","dataSourceHW");
			if(smap.size()==0) {
				log.debug("找不到对应CallID记录:"+callid);
			}else{
				releasecause = smap[0].getAt("releasecause");
			};

			if(releasecause==1281) {
				eliteBean.update("update event set hanguptype=1,stringfield2='1' where ATTACHEDDATA='"+callid+"'","dataSource");
			}else if(releasecause==531){
				eliteBean.update("update event set hanguptype=2,stringfield2='1' where ATTACHEDDATA='"+callid+"'","dataSource");
			}else{
				log.debug("华为releasecause非1281与531值:"+callid);
			};

		}catch (Exception e) {
			log.error("errormsg:", e)
		}
	}

}








